<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$return=array();
$worker = pdo_get('jy_peisong_worker',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
if(empty($worker)){
	exi('您不是分配员！','error','/index/');
}
$return['isopenvoice']=$this->session('isopenvoice')?1:0;
if($_RQ['op']=='main'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$pei['num']=pdo_count('jy_peisong_orderlog',array('uniacid'=>$_SESSION['uniacid']));
	$pei['money']=pdo_getsum('jy_peisong_orderlog',array('uniacid'=>$_SESSION['uniacid']),'order_price');
	$order['money']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1),'price');
	$order['num']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1));
	$pei['numday']=pdo_count('jy_peisong_orderlog',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime));
	$pei['moneyday']=pdo_getsum('jy_peisong_orderlog',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'order_price');
	$order['moneyday']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime),'price');
	$order['numday']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime));
	if($_SESSION['wxapp_id']){
		$return['tmplIds']=array();
	}
	if($_SESSION['os']=='windows'){
		$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'订单概况','datas'=>array(
			array('title'=>'订单笔数/金额','num'=>2,'data'=>array($order['num'],$order['money'])),
			array('title'=>'配送笔数/金额','num'=>2,'data'=>array($pei['num'],$pei['money'])),
			array('title'=>'今日订单笔数/金额','num'=>2,'data'=>array($order['numday'],$order['moneyday'])),
			array('title'=>'今日配送笔数/金额','num'=>2,'data'=>array($pei['numday'],$pei['moneyday'])),
		));
	}
	$return['worker']=$worker;
	$return['pei']=$pei;
	$return['order']=$order;
	set_html('title','分配员中心');
	exi($return);
	
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();	
		$data=array(
				'title'=>$postdata['title'],
				'mobile'=>$postdata['mobile'],
		);
		$worker_id=pdo_getcolumn('jy_peisong_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_peisong_worker',$data,array('id'=>$worker_id));
			exi('修改成功','','main');		 
		}
	}
	$worker=pdo_get('jy_peisong_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
//获取小程序订阅消息ID
if($_RQ['op']=='get_tmpids'){
	$tmplIds=array();
	$tmpid=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新配送任务通知','jy_peisong');
	if($tmpid){
		$tmplIds[]=$tmpid;
	}
	$res['list']=$tmplIds;
	exi($res);
}
?>